//INLINE Pixel BilinearQuadARGB32(Pixel* color0, Pixel* color1, UInt32 u_8,UInt32 v_8)
//{
//    Pixel result;
//
//    UInt32 pm3_8 = (u_8 * v_8)>>8;
//    UInt32 pm2_8 = u_8 - pm3_8;
//    UInt32 pm1_8 = v_8 - pm3_8;
//    UInt32 pm0_8 = 256 - pm1_8 - pm2_8 - pm3_8;
//
//    result.a = (UInt8)((pm0_8 * color0[0].a + pm2_8 * color0[1].a + pm1_8 * color1[0].a + pm3_8 * color1[1].a)>>8);
//    result.r = (UInt8)((pm0_8 * color0[0].r + pm2_8 * color0[1].r + pm1_8 * color1[0].r + pm3_8 * color1[1].r)>>8);
//    result.g = (UInt8)((pm0_8 * color0[0].g + pm2_8 * color0[1].g + pm1_8 * color1[0].g + pm3_8 * color1[1].g)>>8);
//    result.b = (UInt8)((pm0_8 * color0[0].b + pm2_8 * color0[1].b + pm1_8 * color1[0].b + pm3_8 * color1[1].b)>>8);
//}
//R0 = Return value
//R1 = color0
//R2 = color1
//R3 = u_8
//R4 = v_8

//R5 = pm3_8
//lr = 0x00FF00FF
#include <asm.h>

.global C_SYMBOL(BilinearQuadARGB32)
C_SYMBOL(BilinearQuadARGB32):

	STMFD	SP!, {R4-R10, LR}
//.long 0xe7fddefe
	LDR	    R8, [R1], #4                //R6: R6= color0[0], R0: src = src + 4
    LDR     R1, [R1]                    //color0[1] // src = (UInt8*)src + srcPitch + 4
    LDR	    R4, [SP, #32]               //R11: v_8

	MOV	    LR, #16711680               //LR =0X00FF00FF
	ADD	    LR, LR, #255

    MUL     R5, R3, R4                  //R5: (u_8 * v_8)
	MOV	    R5, R5, LSR #8              //R5: pm3_8 = (u_8 * v_8)>>8

/////////////////////////////////////////////////////////////////////////color0[0]

    RSB     R6, R4, #256                //R4: 256 - v_8
    ADD     R6, R6, R5                  //R4: pm0_8 = 256 - v_8 + pm3_8
    SUB     R6, R6, R3                  //R4: 256 - v_8 - u_8 + pm3_8

	AND	    R7, LR, R8, LSR #8          //AG
	MUL	    R9, R7, R6                  //Sum_AG = AG * pm3_8;

	AND	    R8, R8, LR                  //RB
	MUL	    R10, R8, R6                 //Sum_RB = RB * pm3_8;

////////////////////////////////////////////////////////////////////////////color0[1]

    SUB     R6, R3, R5                  //R4: pm2_8 = u_8 - pm3_8;

	AND	    R7, LR, R1, LSR #8          //AG
	MLA	    R9, R7, R6, R9              //Sum_AG += AG * pm2_8;


	AND	    R8, R1, LR                  //RB
	MLA	    R10, R8, R6, R10            //Sum_RB += RB * pm2_8;

//////////////////////////////////////////////////////////////////////color1[0]
	LDR	    R1, [R2], #4                //src = (UInt8*)src + srcPitch
	LDR	    R2, [R2]                    //color1[1], R1 = src

    SUB     R6, R4, R5                  //UInt8 pm1_8 = v_8 - pm3_8;

	AND	    R7, LR, R1, LSR #8          //AG
	MLA	    R9, R7, R6, R9              //Sum_AG += (AG * pm3_8);


	AND	    R8, R1, LR                  //RB
	MLA	    R10, R8, R6, R10            //Sum_RB += (RB * pm3_8);


///////////////////////////////////////////////////////////////////color1[1]

	AND	    R7, LR, R2, LSR #8          //AG
	MLA	    R9, R7, R5, R9

	AND	    R8, R2, LR                  //RB
	MLA	    R10, R8, R5, R10


/////////////////
	AND	    R9, LR, R9, LSR#8           //Sum_AG = (*color>>8) & 0x00FF00FF;
	AND	    R10, LR, R10, LSR#8         //Sum_RB = (*color) & 0x00FF00FF;
	ORR	    R10, R10, R9, LSL#8         //Merge

BilinearQuadARGB32_End:

	LDMFD	SP!, {R4-R10, PC}


